<?php
/*
 * @Author: lokei
 * @Date: 2022-08-16 13:16:33
 * @LastEditors: lokei
 * @LastEditTime: 2022-08-16 21:13:42
 * @Description: 
 */

namespace App\Http\Controllers\Pay;

use App\Common\Tools\ResultTool;
use App\Http\Controllers\Controller;
use App\Models\Platform\ConfModel;
use Illuminate\Http\Request;

class WxConfController extends Controller
{
    /**
     * Create a new controller instance.
     *
     * @return void
     */
    public function __construct()
    {
        //
    }

    function resData($origin) {
        $data = array();
        $data['mchid'] = $origin->mchid;
        $data['signkey'] = $origin->signkey;
        $data['key_path'] = $origin->key_path;
        $data['cert_file'] = $origin->cert_file;
        $data['key_file'] = $origin->key_file;
        return $data;
    }

    //
    public function get() {
        $conf = ConfModel::first();
        $res = ResultTool::success();
        $res['data'] = $this->resData($conf);
        return $res;
    }

    public function set(Request $request) {
        $conf = ConfModel::first();
        $conf->mchid = $request->input('mchid');
        $conf->signkey = $request->input('signkey');
        $conf->key_path = $request->input('key_path');
        $conf->cert_file = $request->input('cert_file');
        $conf->key_file = $request->input('key_file');
        $conf->save();
        return ResultTool::success();
    }
    
}
